use sea_orm::entity::prelude::*;
use sea_orm::Database;
use tokio::sync::OnceCell;

async fn init_conn() -> DatabaseConnection{
    let db_url = std::env::var("DATABASE_URL").expect("DATABASE_URL must be set");
    Database::connect(db_url)
    .await
    .expect("Failed to connect to database")

}

static CONN: OnceCell<DatabaseConnection> = OnceCell::const_new();

pub async fn get_conn() -> DatabaseConnection{
    CONN.get_or_init(init_conn).await.clone()
}